package com.design.YiTong.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.design.YiTong.model.medicinal.MedicinalOrder;
import com.design.YiTong.model.medicinal.MedicinalShop;
import com.design.YiTong.shop.mapper.OrderMapper;
import com.design.YiTong.shop.service.OrderService;
import com.design.YiTong.shop.service.ShopService;
import com.design.common.rabbit.constant.MqConst;
import com.design.common.rabbit.service.RabbitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl extends
        ServiceImpl<OrderMapper, MedicinalOrder> implements OrderService {
    @Autowired
    private RabbitService rabbitService;
    @Autowired
    private ShopService shopService;
    @Override
    public boolean saveOrder(MedicinalOrder medicinalOrder) {
        MedicinalShop medicinalShop =shopService.searchById(medicinalOrder.getMedicinal_id());
        shopService.updateMedinalSum(medicinalOrder);
        if(rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_ORDER, MqConst.ROUTING_ORDER, medicinalShop)){
            return true;
        }
        return false;
    }

    @Override
    public IPage<MedicinalOrder> showorder(Page<MedicinalOrder> pageParam) {
        QueryWrapper<MedicinalOrder> wrapper=new QueryWrapper<>();
        IPage<MedicinalOrder> pages = baseMapper.selectPage(pageParam,wrapper);
        return pages;
    }
}
